//
//  HQVenderViewController.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/5/12.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQVenderViewController.h"
#import "HQVenderCell.h"
#import "HQShopViewController.h"
#import "HQAddFactoryView.h"

@interface HQVenderViewController ()<HQAddFactoryViewDelegate>
{
    UIView *_view1;
    UIScrollView *_view2;
    HQAddFactoryView *_v2;
}
@end

@implementation HQVenderViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"厂家";
    
    [self addTopView];
    
    _dataSource = [[NSMutableArray alloc]initWithArray:@[@1,@2,@3,@4,@5,@1,@2,@3,@4,@5]];
}

-(void)addTopView{
    _titleView = [[FindTitleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44) withArray:@[@"合作厂家",@"推荐厂家"]];
    _titleView.backgroundColor = [UIColor whiteColor];
    [_topView addSubview:_titleView];
    _titleView.itemClickBlock = ^(UIButton *button){
        NSLog(@"触发的方法");
    };
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HQVenderCell *cell = [HQVenderCell cellWithTableView:tableView];
    [cell.editButton addTarget:self action:@selector(editItem) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

-(void)editItem{
    UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了取消按钮");
    }];
    [cancelAction setValue:[self colorHexValue:0x233040] forKey:@"titleTextColor"];
   
    UIAlertAction *takeAction = [UIAlertAction actionWithTitle:@"编辑" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 
    }];
    [takeAction setValue:[self colorHexValue:0x233040] forKey:@"titleTextColor"];

    UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];
    [photoAction setValue:[self colorHexValue:0x233040] forKey:@"titleTextColor"];

    // 添加响应方式
    [actionSheetController addAction:cancelAction];
    [actionSheetController addAction:takeAction];
    [actionSheetController addAction:photoAction];
    // 显示
    [self presentViewController:actionSheetController animated:YES completion:nil];
}

/**
 添加工厂
 
 @param sender 添加按钮
 */
- (IBAction)addFactoryItem:(id)sender {
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    
    //
    _view1 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _view1.backgroundColor = [UIColor blackColor];
    _view1.alpha = 0.3;
    [keyWindow addSubview:_view1];
    UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hidden2)];
    [_view2 addGestureRecognizer:g];
    
    //
    _view2 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _view2.backgroundColor = [UIColor clearColor];
    _view2.contentSize= CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT+200);
    [keyWindow addSubview:_view2];
    
    //
    _v2 = [HQAddFactoryView loadFactoryView];
    _v2.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _v2.delegate = self;
    [_view2 addSubview:_v2];
}

-(void)cancelItem{
    [self hidden2];
}

-(void)contentItem{
    [self hidden2];
}

-(void)hidden2{
    [_view1 removeFromSuperview];
    [_view2 removeFromSuperview];
    [_v2 removeFromSuperview];
}

@end
